package com.jhgsys.internal.incentive.service.impl;

import com.jhgsys.internal.incentive.entity.IncentiveRewardClauseRuleRecord;
import com.jhgsys.internal.incentive.mapper.IncentiveRewardClauseRuleRecordMapper;
import com.jhgsys.internal.incentive.service.IIncentiveRewardClauseRuleRecordService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 奖励规则变更记录 Service实现
 *
 * @author zjb
 * @date 2024-08-30 09:51:18
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class IncentiveRewardClauseRuleRecordServiceImpl extends ServiceImpl<IncentiveRewardClauseRuleRecordMapper, IncentiveRewardClauseRuleRecord> implements IIncentiveRewardClauseRuleRecordService {

    /**
     * 查询（分页）
     * @author zjb
     * @date 2024-08-30 09:51:18
     * @param request QueryRequest
     * @param incentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord
     * @return IPage<IncentiveRewardClauseRuleRecord>
    */
    @Override
    public IPage<IncentiveRewardClauseRuleRecord> findIncentiveRewardClauseRuleRecordPage(QueryRequest request, IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) {
        LambdaQueryWrapper<IncentiveRewardClauseRuleRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveRewardClauseRuleRecord::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<IncentiveRewardClauseRuleRecord> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author zjb
     * @date 2024-08-30 09:51:18
     * @param incentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord
     * @return List<IncentiveRewardClauseRuleRecord>
     */
    @Override
    public List<IncentiveRewardClauseRuleRecord> findIncentiveRewardClauseRuleRecordList(IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) {
	    LambdaQueryWrapper<IncentiveRewardClauseRuleRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IncentiveRewardClauseRuleRecord::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author zjb
    * @date 2024-08-30 09:51:18
    * @param id
    * @return IncentiveRewardClauseRuleRecord
    */
    @Override
    public IncentiveRewardClauseRuleRecord findIncentiveRewardClauseRuleRecordById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author zjb
     * @date 2024-08-30 09:51:18
     * @param incentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord
     */
    @Override
    @Transactional
    public void createIncentiveRewardClauseRuleRecord(IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) {
        incentiveRewardClauseRuleRecord.setCreatedTime(new Date());
        this.save(incentiveRewardClauseRuleRecord);
    }

    /**
     * 修改
     * @author zjb
     * @date 2024-08-30 09:51:18
     * @param incentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord
     */
    @Override
    @Transactional
    public void updateIncentiveRewardClauseRuleRecord(IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord) {
        incentiveRewardClauseRuleRecord.setUpdatedTime(new Date());
        this.saveOrUpdate(incentiveRewardClauseRuleRecord);
    }

    /**
     * 逻辑删除
     * @author zjb
     * @date 2024-08-30 09:51:18
     * @param incentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord
     * @param incentiveRewardClauseRuleRecordIds incentiveRewardClauseRuleRecordIds
     */
    @Override
    @Transactional
    public void deleteIncentiveRewardClauseRuleRecord(IncentiveRewardClauseRuleRecord incentiveRewardClauseRuleRecord,String incentiveRewardClauseRuleRecordIds) {
        List<String> list = Arrays.asList(incentiveRewardClauseRuleRecordIds.split(StringPool.COMMA));
        this.baseMapper.update(incentiveRewardClauseRuleRecord,new LambdaQueryWrapper<IncentiveRewardClauseRuleRecord>().in(IncentiveRewardClauseRuleRecord::getClauseRuleRecordId,list));
	}

    /**
    * 物理删除
    * @author zjb
    * @date 2024-08-30 09:51:18
    * @param incentiveRewardClauseRuleRecordIds incentiveRewardClauseRuleRecordIds
    */
    @Override
    @Transactional
    public void physicallyDeleteIncentiveRewardClauseRuleRecord(String incentiveRewardClauseRuleRecordIds) {
        List<String> list = Arrays.asList(incentiveRewardClauseRuleRecordIds.split(StringPool.COMMA));
        LambdaQueryWrapper<IncentiveRewardClauseRuleRecord> wapper = new LambdaQueryWrapper<>();
        wapper.in(IncentiveRewardClauseRuleRecord::getClauseRuleRecordId,list);
        this.remove(wapper);
    }
}
